<template>
	<view class="back-view" @touchmove.stop.prevent="moveHandle">
		<view class="view-background"></view>
		<view class="white-view-back">
			<view class="top-back">
				<view class="top-name">审核案件</view>
				<view class="close-back" @click="closeBtnAction">
					<image class="close-img" src="../../../static/close.png"></image>
				</view>
			</view>

			<view class="top-line"></view>
			<view style="width: 300px;">
				<uni-forms ref="baseForm" :modelValue="baseFormData">
					<uni-forms-item label="审核结果：" labelWidth="90" labelAlign="right" required>
						<uni-data-checkbox selectedColor="#2DA9C5" v-model="baseFormData.result"
							:localdata="resultArr" />
					</uni-forms-item>
					<uni-forms-item v-if="baseFormData.result" label="审核备注：" labelWidth="90" labelAlign="right"
						required>
						<uni-easyinput type="textarea" v-model="baseFormData.failMsg" placeholder="请输入不通过的原因" />
					</uni-forms-item>
				</uni-forms>
			</view>
			<view class="bottom-back">
				<view class="bottom-btn bottom-btn-cancel" @click="closeBtnAction">取消</view>
				<view class="bottom-btn" @click="saveAction">保存</view>
			</view>
		</view>
	</view>
</template>

<script>
	let app = ''

	export default {
		props: {
			itemID: {
				type: String,
				default: ''
			},
		},
		data() {
			return {
				role: '', //当前登录角色
				roleUrl: '',
				baseFormData: {
					'result': '',
					'failMsg': '',
				},
				resultArr: [{
					text: '通过',
					value: 0
				}, {
					text: '不通过',
					value: 1
				}, ]
			}
		},
		mounted() {
			var _this = this;
			app = getApp()
			_this.role = app.globalData.role
			_this.roleUrl = _this.$roleUrl({
				tab: _this.role
			})
		},
		methods: {
			async saveAction() {
				if (this.baseFormData.result !== 0 && this.baseFormData.result !== 1) {
					uni.showToast({
						title: '请选择审核结果',
						icon: 'none'
					})
					return;
				}

				if (this.baseFormData.result === 1 && !this.baseFormData.failMsg) {
					uni.showToast({
						title: '请输入不通过的原因',
						icon: 'none'
					})
					return;
				}
				let _this = this

				var parms = {
					'caseId': this.itemID,
					'failMsg': this.baseFormData.failMsg,
				}
				console.log(parms)

				var url = `/${_this.roleUrl}/case/review/0`;
				if (this.baseFormData.result === 1) {
					url = `/${_this.roleUrl}/case/review/1`;
				}

				const res = await this.$myRequest({
					url: url,
					method: 'PUT',
					data: parms
				})
				console.log('返回结果', res)

				if (res.data.code == 200) {
					uni.showToast({
						title: '审核成功'
					})
					_this.$emit("successBack");
					_this.closeBtnAction()
				}
			},
			closeBtnAction() {
				this.$emit('checkClose')
			},
			moveHandle() {
				return true
			},
		},
	}
</script>

<style>
	.back-view {
		position: fixed;
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
		z-index: 199;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.view-background {
		position: absolute;
		width: 100%;
		height: 100%;
		z-index: 100;
		background-color: rgba(0, 0, 0, 0.3);
	}

	.white-view-back {
		width: 320px;
		height: 310px;
		padding: 24px;
		max-height: 310px;
		background-color: white;
		margin-top: -50px;
		border-radius: 4px;
		z-index: 101;
		position: absolute;
	}

	.top-back {
		display: flex;
		justify-content: space-between;
	}

	.top-name {
		font-size: 18px;
		font-weight: normal;
		color: #333333;

	}

	.close-back {
		cursor: pointer;
		width: 20px;
		height: 20px;
		display: flex;
		justify-content: center;
		align-items: center;
		cursor: pointer;
	}

	.close-img {
		width: 12px;
		height: 12px;
	}

	.top-line {
		height: 1px;
		background: #EEEEEE;
		width: 100%;
		margin-top: 20px;
		margin-bottom: 20px;
	}

	.bottom-back {
		bottom: 0px;
		width: 100%;
		display: flex;
		justify-content: flex-end;
		align-items: center;
		position: absolute;
		height: 60px;
		right: 16px;
	}

	.bottom-btn {
		cursor: pointer;
		width: 104px;
		height: 32px;
		background: #2DA9C5;
		border-radius: 2px;
		color: #FFFFFF;
		font-size: 14px;
		display: flex;
		justify-content: center;
		align-items: center;
		cursor: pointer;
	}

	.bottom-btn-cancel {
		margin-right: 10px;
		background: #FFFFFF;
		border: 1px solid #EEEEEE;
		color: #333333;
	}
</style>
